/**
 * 
 */
package org.dgm.nw.common;

import org.apache.log4j.Logger;
import org.dgm.nw.core.control.SpringBeanFactory;
import org.dgm.nw.core.exception.BusiException;

/**
 * MenuAction工厂<br>
 * 用以实例化MenuAction对象
 * 
 * @author wangwz
 * @date Sep 1, 2010
 * @version RCS: $Id: MenuActionFactory.java 684515 2012-03-30 09:45:07Z humj $
 */
public class MenuActionFactory {
	/**
	 * Logger for this class
	 */
	private static final Logger log = Logger
			.getLogger(MenuActionFactory.class);

	/**
	 * 实例化MenuAction对象
	 * 
	 * @param menuId
	 * @param clazz
	 * @return
	 * @throws Exception
	 */
	public static Object getMenuAction(String menuId, Class clazz)
			throws Exception {

		Object obj = SpringBeanFactory.getBeanFactory().getBean(
				"MENU_" + menuId + "_" + clazz.getName(), clazz, true, null);

		if (obj != null && obj instanceof BaseMenuAction) {
			log.info("得到指定menuAction对象,menuId:"+menuId);
			BaseMenuAction baseMenuAction = (BaseMenuAction) obj;
			baseMenuAction.setMenuId(menuId);
			return obj;
		} else {
			log.error("class:[" + clazz.getSimpleName() + "]必须继承["
					+ BaseMenuAction.class.getSimpleName() + "]");
			throw new BusiException("class:[" + clazz.getSimpleName() + "]必须继承["
					+ BaseMenuAction.class.getSimpleName() + "]",null);
		}
	}
}
